/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Engine2D.geometry;

import Engine2D.math.Matrix3f;
import java.util.ArrayList;

/**
 *
 * @author Garys
 */
public class Polygon extends Shape{
    private boolean isClosed= false;
    
    /**
     * 
     */
    public Polygon(){
        this.points = new float[0];
    }
    
    /**
     * 
     * @param points
     */
    public Polygon(float[] points){
    
        this.points = points;
    }

    /**
     * 
     */
    @Override
    protected void createPoints() {
        
    }

    /**
     * 
     * @param transform
     * @return
     */
    @Override
    public Shape transform(Transform transform) {
        Polygon resultPolygon = new Polygon();
        float result[] = new float[points.length];
        transform.transform(points, 0, result, 0, points.length / 2);
        resultPolygon.points = result;
        
        
        
        return resultPolygon;
    }
    
    
    /**
     * 
     * @param transform
     * @return
     */
    public Shape transform2(Transform transform) {
        Polygon resultPolygon = new Polygon();
        float result[] = new float[points.length];
        transform.transform2(points, 0, result, 0, points.length / 2);
        resultPolygon.points = result;
        
        
        
        return resultPolygon;
    }
    
    /**
     * 
     * @param transform
     * @return
     */
    public Shape transform3(Transform transform) {
        Polygon resultPolygon = new Polygon();
        float result[] = new float[points.length];
        transform.transform3(points, 0, result, 0, points.length / 2);
        resultPolygon.points = result;
        
        
        
        return resultPolygon;
    }
    
  
    /**
     * 
     * @param x
     * @param y
     */
    public void addPoint(float x, float y) {
        
        ArrayList tempPoints = new ArrayList();
        
       
        for (int i = 0; i < points.length; i++) {
            tempPoints.add(new Float(points[i]));
        }
        
        tempPoints.add(new Float(x));
        tempPoints.add(new Float(y));
        points = new float[tempPoints.size()];
        for(int i=0;i<tempPoints.size();i++) {
            points[i] = ((Float)tempPoints.get(i)).floatValue();
        }
    }
    
    /**
     * 
     * @param isClosed
     */
    public void setClosed(boolean isClosed) {
        this.isClosed = isClosed;
    }
    
    /**
     * 
     * @return
     */
    public boolean closed() {
        return isClosed;
    }
    
}
